<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="chrome=1;IE=edge">
    <meta name="viewport" content="user-scalable=no">
    <!-- vue2 -->
    <script src="/examples/js/vue.min.js"></script>
    <!-- 示例演示-公共样式 -->
    <link rel="stylesheet" href="/examples/css/railView.css" type="text/css" />
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <!-- RailUnit 样式 -->
    <link rel="stylesheet" href="/RailUnit/RailUnit.umd.css" type="text/css">
    <!-- RailUnit 插件 -->
    <script type="text/javascript" src="/RailUnit/RailUnit.umd.js" charset="utf-8"></script>
</head>
<body>
    <div id="app">
        <div id="buttom-container">
            <el-button type="info" size="small" id="shadowBtn" @click="isShadow">开启阴影</el-button>
            <el-button type="info" size="small" @click="showCard = true">设置阴影</el-button>
            <el-button type="info" size="small" @click="optimget">获取参数</el-button>
            <el-button type="info" size="small" @click="resetToDefault">恢复默认</el-button>
        </div>
        <el-card class="box-card" v-show="showCard" style="width: 400px;">
            <div slot="header" class="clearfix">
              <span>设置</span>
              <el-button class="close-btn" type="text" @click="showCard = false">×</el-button>
            </div>
            <div class="card-container">
                <el-form 
                    ref="form" 
                    :model="formValues" 
                    label-width="110px"
                >
                    <el-form-item label="阴影透明度：">
                        <el-input v-model.number="formValues.opacity" placeholder="可输入0-1"></el-input>
                    </el-form-item>
                    <el-form-item label="阴影颜色：">
                        <el-color-picker v-model.number="formValues.color"></el-color-picker>
                    </el-form-item>
                    <el-form-item label="阴影分辨率：">
                        <el-input v-model.number="formValues.resolution" placeholder="请输入阴影分辨率"></el-input>
                    </el-form-item>
                    <el-form-item label="阴影虚化直径：">
                        <el-input v-model.number="formValues.distance" placeholder="请输入阴影虚化直径"></el-input>
                    </el-form-item>
                </el-form>
                <div class="modal-footer">
                    <el-button size="small" type="primary" @click="handleSubmit">确认</el-button>
                </div>
            </div>
        </el-card>
        <div id="viewer" style="width:100%;height:100%;position:relative;float:left"></div>
    </div>
    
    <script id="viewerStartup" type="module">
        const vm = new Vue({
            el: '#app',
            data: {
                bimViewer: null,
                formRef: null,
                showCard: false,
                formValues: {
                    opacity: 0.5,
                    color: '',
                    resolution: 500,
                    distance: 1
                }
            },
            mounted () {
                this.bimViewerFn()
            },
            methods: {
                // 初始化模型
                bimViewerFn() {
                    this.bimViewer = new MyViewer({
                        serverUrl: '/RailUnit/',
                        containerElement: document.getElementById('viewer'),
                        nodeVisible: false
                    })
                    this.bimViewer.loadModel2('jianzhu')
                },
                isShadow() {
                    const shadowBtn = document.getElementById("shadowBtn");
                    console.log(shadowBtn);
                    if (shadowBtn.innerText === "开启阴影") {
                        this.bimViewer.enableShadow(true);
                        shadowBtn.innerText ="关闭阴影"
                    } else {
                        this.bimViewer.enableShadow(false);
                        shadowBtn.innerText ="开启阴影"
                    }
                },
                handleSubmit () {
                    const { opacity, color, resolution, distance } = this.formValues
                    console.log(this.formValues);
                    const red = Number('0x' + color.substring(1, 3));
                    const green = Number('0x' + color.substring(3, 5));
                    const blue = Number('0x' + color.substring(5, 7));

                    this.bimViewer.setShadow(opacity, { r: red, g: green, b: blue }, resolution, distance);
                },
                resetToDefault () {
                    this.bimViewer.resetDefaultShodaw();
                },
                optimget () {
                    let res = this.bimViewer.getShodawSettion();
                    var description = ""; 
                    for(var i in res){ 
                        var property = '';
                        console.log(typeof res[i] === 'object');
                        if (typeof res[i] === 'object') {
                            property = JSON.stringify(res[i])
                        } else {
                            property = res[i]
                        }
                        description += i + " = " + property + " \n"; 
                    } 
                    alert(description); 
                },
            }
        })
        
    </script>
</body>
</html>
